#pragma once
#include "time.h"
#include <vector>
#include "LFEventHandler.h"
#include "AlarmEvent.h"
#include "Reactor.h"
#include "SOCK_Acceptor.h"
#include "SOCK_Stream.h"

namespace Network 
{
	typedef struct AlarmEventItem_ {
		AlarmEvent event;
		time_t timestamp;

		AlarmEventItem_(AlarmEvent event_, time_t timestamp_) : event(event_), timestamp(timestamp_) {}

	} AlarmEventItem;

	//comparer
	struct AlarmEventItemPriorityComparer{
		inline bool operator()(const AlarmEventItem &a, const AlarmEventItem &b) {
			return a.event.priority < b.event.priority;
		}
	};
	

	class AlarmEventHandler : public EventHandler
	{
		private:
		SOCK_Stream peerStream;
		Reactor *reactor;
		bool status;

		//SOCK_Acceptor* listener;
		std::vector<AlarmEventItem> alarms;
	public:
		AlarmEventHandler();
		~AlarmEventHandler() {}
		AlarmEventHandler(const SOCK_Stream &stream);
		virtual void HandleEvent (HANDLE handle, EventType eventType);
		virtual HANDLE GetHandle();
		
		bool IsRunning();

		void handleRead(HANDLE handle); 
	};
}
